package com.kzd.btgame.callback

import android.content.Intent
import android.net.Uri
import android.webkit.WebResourceRequest
import android.webkit.WebResourceResponse
import android.webkit.WebView
import android.webkit.WebViewClient
import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.LogUtils

open class AppWebViewClient : WebViewClient() {
    override fun shouldOverrideUrlLoading(
        view: WebView?, request: WebResourceRequest?
    ): Boolean {
        if (request == null) {
            return false
        }
        try {
            val url = request.url.toString()
            LogUtils.e(url)
            if (url.startsWith("http:") || url.startsWith("https:")) {
                return false
            }
            val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
            ActivityUtils.startActivity(intent)
        } catch (e: Exception) {
            return false
        }
        return true
    }

    override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
        if (url == null) {
            return false
        }
        try {
            LogUtils.e(url)
            if (url.startsWith("http:") || url.startsWith("https:")) {
                return false
            }
            val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
            ActivityUtils.startActivity(intent)
        } catch (e: Exception) {
            return false
        }
        return true
    }
}